package com.gitee.wsl.prism4j.languages

import com.gitee.wsl.prism4j.Prism4j
import com.gitee.wsl.prism4j.Prism4j.Companion.grammar
import com.gitee.wsl.prism4j.Prism4j.Companion.pattern
import com.gitee.wsl.prism4j.Prism4j.Companion.token
import com.gitee.wsl.prism4j.Prism4j.Pattern

@Suppress("unused")
object Prism_clike {
    fun create(prism4j: Prism4j): Prism4j.Grammar {
        return grammar(
            "clike",
            token(
                "comment",
                pattern(Pattern.compile("(^|[^\\\\])\\/\\*[\\s\\S]*?(?:\\*\\/|$)"), true),
                pattern(Pattern.compile("(^|[^\\\\:])\\/\\/.*"), true, true)
            ),
            token(
                "string",
                pattern(Pattern.compile("([\"'])(?:\\\\(?:\\r\\n|[\\s\\S])|(?!\\1)[^\\\\\\r\\n])*\\1"), false, true)
            ),
            token(
                "class-name",
                pattern(
                    Pattern.compile("((?:\\b(?:class|interface|extends|implements|trait|instanceof|new)\\s+)|(?:catch\\s+\\())[\\w.\\\\]+"),
                    true,
                    false,
                    null,
                    grammar("inside", token("punctuation", pattern(Pattern.compile("[.\\\\]"))))
                )
            ),
            token(
                "keyword",
                pattern(Pattern.compile("\\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\\b"))
            ),
            token("boolean", pattern(Pattern.compile("\\b(?:true|false)\\b"))),
            token("function", pattern(Pattern.compile("[a-z0-9_]+(?=\\()", Pattern.CASE_INSENSITIVE))),
            token(
                "number",
                pattern(
                    Pattern.compile(
                        "\\b0x[\\da-f]+\\b|(?:\\b\\d+\\.?\\d*|\\B\\.\\d+)(?:e[+-]?\\d+)?",
                        Pattern.CASE_INSENSITIVE
                    )
                )
            ),
            token(
                "operator",
                pattern(Pattern.compile("--?|\\+\\+?|!=?=?|<=?|>=?|==?=?|&&?|\\|\\|?|\\?|\\*|\\/|~|\\^|%"))
            ),
            token("punctuation", pattern(Pattern.compile("[{}\\[\\];(),.:]")))
        )
    }
}
